from application.util.MysqlUtil import mysql_db
from sqlalchemy import String, Text, Integer
from sqlalchemy.orm import mapped_column, Mapped
from application.util.TimeUtil import now_timestamp


class ImageModel(mysql_db.Model):
    __tablename__ = "image"
    id: Mapped[str] = mapped_column(String(32), primary_key=True, unique=True, comment="主键，长度为32，唯一")
    unique_id: Mapped[str] = mapped_column(String(255), nullable=False, comment="图片三方ID，长度为255，不能为NULL")
    url: Mapped[str] = mapped_column(Text, nullable=False, comment="图片链接，不能为NULL")
    # 更新时间，默认为now_timestamp生成，更新时为now_timestamp生成
    update_timestamp: Mapped[int] = mapped_column(Integer, insert_default=now_timestamp(), onupdate=now_timestamp(),
                                                  nullable=True, comment="更新时间戳")
    # 创建时间，默认为now_timestamp生成的
    create_timestamp: Mapped[int] = mapped_column(Integer, insert_default=now_timestamp(), nullable=True,
                                                  comment="创建时间戳")
